package com.ncloud.aaaa.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import com.ncloud.aaaa.model.Menu;

public interface MenuRepository extends CrudRepository<Menu, Long> {
	Page<Menu> findAll(Pageable pageable);

	@Query("select distinct a from Menu a,RoleSubsysMenu c,UserRole d where d.id.userId = ?1 and d.id.roleId = c.roleId and c.menuId = a.id and a.state ='1' order by a.parentId,a.sort")
	List<Menu> getMenusByUserId(Long userId);
	
	@Query("select distinct c from UserRole a,RoleSubsysMenu b,Menu c where a.id.userId = ?1 "
			+ " and a.id.roleId = b.roleId and b.subsysId = ?2 and b.menuId = c.id and c.state='1' order by c.parentId,c.sort")
	List<Menu> getMenusBySubsysAndUserId(Long userId, Long subsysId);
}
